import React from 'react'
import {DatePicker, List} from 'antd-mobile'
import { connect } from 'mirrorx'
import Trial from '../../trial'

class App extends React.Component {
  render () {
    const Lang = window.LangMessage || {}
    const { getFieldProps } = this.props.form
    const {initInfo = {}, trialPrice} = this.props
    let initFactors = Trial.getInitTrialFactors()
    let minDate = new Date()
    minDate.setDate(minDate.getDate() + 1)
    let maxDate = new Date()
    maxDate.setMonth(maxDate.getMonth() + 1)

    let initValue = initInfo['effectiveTime'] || initFactors['policyEffectDate'] || minDate
    if (typeof initValue === 'string') {
      initValue = new Date(initValue.replace(/-/g, '/'))
    }
    return (
      <div className='mt40 mb10 pl20 pr40 bgfw'>
        <DatePicker
          {...getFieldProps('effectiveTime', {
            initialValue: initValue,
            rules: [{
              required: true
            }]
          })}
          onOk={value => trialPrice && trialPrice('policyEffectDate', value)}
          mode='date'
          minDate={minDate}
          maxDate={maxDate}
        >
          <List.Item arrow='horizontal'>{'発効日' || Lang.effective_date || '生效日期'}</List.Item>
        </DatePicker>
      </div>

    )
  }
}

export default connect(state => {
  return {initInfo: state.insureModel.initInfo}
})(App)
